package com.mdd.admin.controller.yylq;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.yylq.ITAppCityService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.yylq.TAppCityCreateValidate;
import com.mdd.admin.validate.yylq.TAppCitySearchValidate;
import com.mdd.admin.validate.yylq.TAppCityUpdateValidate;
import com.mdd.admin.vo.yylq.TAppCityDetailVo;
import com.mdd.admin.vo.yylq.TAppCityListedVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@ApiIgnore
@RestController
@RequestMapping("api/city")
@Api(tags = "羊羊领企---城市管理")
public class TAppCityController {

    @Resource
    ITAppCityService iTAppCityService;

    @GetMapping("/list")
    @ApiOperation(value="城市列表")
    public AjaxResult<PageResult<TAppCityListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated TAppCitySearchValidate searchValidate) {
        PageResult<TAppCityListedVo> list = iTAppCityService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="城市详情")
    public AjaxResult<TAppCityDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        TAppCityDetailVo detail = iTAppCityService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "城市新增")
    @PostMapping("/add")
    @ApiOperation(value="城市新增")
    public AjaxResult<Object> add(@Validated @RequestBody TAppCityCreateValidate createValidate) {
        iTAppCityService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "城市编辑")
    @PostMapping("/edit")
    @ApiOperation(value="城市编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody TAppCityUpdateValidate updateValidate) {
        iTAppCityService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "城市删除")
    @PostMapping("/del")
    @ApiOperation(value="城市删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iTAppCityService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
